import router from './router'
import store from './store'
import http from 'hitcxedu-http'

// path 白名单
const whiteList = []

router.beforeEach(async (to, from, next) => {
  const { path } = to;

  http.clearHttpRequestingList()
  // 白名单放行
  if (whiteList.indexOf(to.path) !== -1) {
    return next()
  }

<<<<<<< HEAD
  const { token, routes } = store.getters;
  // 是否已登录
  if (token) {
    if (path === '/login') return next('/')
    if (!routes.length) {
      store.dispatch('common/generateRoutes')
    }

    return next()
  }

=======
  const hasToken = store.getters.token;
  // 是否已登录
  if (hasToken) {
    if (path === '/login') return next('/')

    return next()
  }
  
  return next()
>>>>>>> 85d0debcca44c4a451c9e968272089f1bfdcaf45
  if (path !== '/login') {
    next('/login')
  } else {
    next()
  }
})